package com.winning.bi.processer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.winning.bi.data.Message;
import com.winning.bi.jdbc.dao.DaoImp;

/**
 * 
 * @author 张大川
 *
 */
public class DbProcess extends EventProcesser {
	/**
	 * 
	 */
	private static Logger log = LoggerFactory.getLogger(DbProcess.class);

	@Override
	public boolean process(Message e, String target) {
		DaoImp dataSource = (DaoImp) ac.getBean("daoImp");
		List<String> list2 = new ArrayList<String>();
		//log.info(JSON.toJSONString(e));

		Map<String, Object> map = e.getMap();
  
		for (Map.Entry<String, Object> entry : map.entrySet()) {
			if (map.get(entry.getKey())!=null)
					{list2.add(entry.getKey());}
		}
		String sw[] = new String[list2.size()];
		for (int i = 0; i < list2.size(); i++) {
			sw[i] = list2.get(i);
		}
		//System.out.println(JSON.toJSONString(sw));
		boolean b = true;
		try {
			dataSource.insertMap(e.getMap(), e.getTarget(), sw);
		} catch (Exception e1) {

			b = false;
		}
		log.debug(JSON.toJSONString(e.getMap()));
	
		return b;
	}

}
